package cn.retalsystem.controller;

import cn.retalsystem.bean.User;
import cn.retalsystem.service.UserService;
import cn.retalsystem.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: 王劲威
 * @Date: 2019/11/2 12:51
 * @Version 1.0
 * @描述：用户管理模块
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/init")
    public String init(Model model,String username){
        System.out.println(username);
        int count = userService.getCount(username);
        model.addAttribute("count",count);
        model.addAttribute("username",username);
        return "user_management";
    }



    /**
     * 将查询的用户信息显示在前端
     */
    @RequestMapping("/getshow")
    @ResponseBody
    public List<UserVo> toAllUsers(String username){
        return userService.selectAllUsers(username);
    }


    @RequestMapping("/table")
    @ResponseBody
    public List<UserVo> ShowPage(Integer page, Integer limit,String username){
        List<UserVo> userVoList = userService.getallUsers(page, limit,username);
        return userVoList;
    }

    @RequestMapping("/dels")
    @ResponseBody
    public Integer DeleteUsers(Integer id){
        System.out.println(id);
        Integer result = userService.DeleteUsers(id);
        System.out.println(result);
        return result;
    }
}
